home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / common / client / missionDownload.cs < prev    next >
Text File  |  2005-11-23  |  3KB  |  110 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //----------------------------------------------------------------------------
  7. // Mission Loading
  8. // Server download handshaking.  This produces a number of onPhaseX
  9. // calls so the game scripts can update the game's GUI.
  10. //
  11. // Loading Phases:
  12. // Phase 1: Download Datablocks
  13. // Phase 2: Download Ghost Objects
  14. // Phase 3: Scene Lighting
  15. //----------------------------------------------------------------------------
  16.  
  17. //----------------------------------------------------------------------------
  18. // Phase 1 
  19. //----------------------------------------------------------------------------
  20.  
  21. function clientCmdMissionStartPhase1(%seq, %missionName, %musicTrack)
  22. {
  23.    // These need to come after the cls.
  24.    echo ("*** New Mission: " @ %missionName);
  25.    echo ("*** Phase 1: Download Datablocks & Targets");
  26.    onMissionDownloadPhase1(%missionName, %musicTrack);
  27.    commandToServer('MissionStartPhase1Ack', %seq);
  28. }
  29.  
  30. function onDataBlockObjectReceived(%index, %total)
  31. {
  32.    onPhase1Progress(%index / %total);
  33. }
  34.  
  35. //----------------------------------------------------------------------------
  36. // Phase 2
  37. //----------------------------------------------------------------------------
  38.  
  39. function clientCmdMissionStartPhase2(%seq,%missionName)
  40. {
  41.    onPhase1Complete();
  42.    echo ("*** Phase 2: Download Ghost Objects");
  43.    purgeResources();
  44.    onMissionDownloadPhase2(%missionName);
  45.    commandToServer('MissionStartPhase2Ack', %seq);
  46. }
  47.  
  48. function onGhostAlwaysStarted(%ghostCount)
  49. {
  50.    $ghostCount = %ghostCount;
  51.    $ghostsRecvd = 0;
  52. }
  53.  
  54. function onGhostAlwaysObjectReceived()
  55. {
  56.    $ghostsRecvd++;
  57.    onPhase2Progress($ghostsRecvd / $ghostCount);
  58. }
  59.  
  60. //----------------------------------------------------------------------------
  61. // Phase 3
  62. //----------------------------------------------------------------------------
  63.  
  64. function clientCmdMissionStartPhase3(%seq,%missionName)
  65. {
  66.    onPhase2Complete();
  67.    StartClientReplication();
  68.    StartFoliageReplication();
  69.    echo ("*** Phase 3: Mission Lighting");
  70.    $MSeq = %seq;
  71.    $Client::MissionFile = %missionName;
  72.  
  73.    // Need to light the mission before we are ready.
  74.    // The sceneLightingComplete function will complete the handshake 
  75.    // once the scene lighting is done.
  76.    if (lightScene("sceneLightingComplete", ""))
  77.    {
  78.       error("Lighting mission....");
  79.       schedule(1, 0, "updateLightingProgress");
  80.       onMissionDownloadPhase3(%missionName);
  81.       $lightingMission = true;
  82.    }
  83. }
  84.  
  85. function updateLightingProgress()
  86. {
  87.    onPhase3Progress($SceneLighting::lightingProgress);
  88.    if ($lightingMission)
  89.       $lightingProgressThread = schedule(1, 0, "updateLightingProgress");
  90. }
  91.  
  92. function sceneLightingComplete()
  93. {
  94.    echo("Mission lighting done");
  95.    onPhase3Complete();
  96.    
  97.    // The is also the end of the mission load cycle.
  98.    onMissionDownloadComplete();
  99.    commandToServer('MissionStartPhase3Ack', $MSeq);
  100. }
  101.  
  102. //----------------------------------------------------------------------------
  103. // Helper functions
  104. //----------------------------------------------------------------------------
  105.  
  106. function connect(%server)
  107. {
  108.    %conn = new GameConnection();
  109.    %conn.connect(%server);
  110. }